package com.sooth.micro.process.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sooth.common.core.domain.R;
import com.sooth.common.log.annotation.Log;
import com.sooth.common.web.core.BaseController;
import com.sooth.micro.process.service.IMicroProcessService;
import com.sooth.micro.process.view.MicroProcessBo;
import com.sooth.micro.process.view.MicroProcessDto;
import com.sooth.micro.process.view.MicroProcessVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 流程设计信息
 *
 * @author Lion Li
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/micro/process")
public class MicroProcessController extends BaseController {

    private final IMicroProcessService processService;

    /**
     * 获取流程设计列表
     */
    @SaCheckPermission("system:micro-process:query")
    @GetMapping("/list")
    public R<List<MicroProcessVo>> list(MicroProcessDto microProcessDto) {
        return R.ok(processService.selectList(microProcessDto));
    }


    /**
     * 根据流程设计编号获取详细信息
     *
     * @param id 流程设计ID
     */
    @SaCheckPermission("system:micro-process:query")
    @GetMapping(value = "/query")
    public R<MicroProcessBo> query(@RequestParam Long id) {
        return R.ok(processService.selectById(id));
    }

    /**
     * 根据应用编号获取详细信息
     *
     * @param appId 应用id
     */
    @SaCheckPermission("system:micro-process:query")
    @GetMapping(value = "/queryByAppId")
    public R<MicroProcessBo> queryByAppId(@RequestParam Long appId) {
        return R.ok(processService.queryByAppId(appId));
    }

    /**
     * 保存流程设计
     */
    @SaCheckPermission("system:micro-process:save")
    @Log(title = "流程设计管理", message = "新增流程设计")
    @PostMapping("/save")
    public R<Void> save(@RequestBody MicroProcessBo microProcess) {
        return toAjax(processService.save(microProcess));
    }

    /**
     * 修改流程设计
     */
    @SaCheckPermission("system:micro-process:edit")
    @Log(title = "流程设计管理", message = "修改流程设计")
    @PutMapping("/edit")
    public R<Void> edit(@Validated @RequestBody MicroProcessBo microProcess) {
        return toAjax(processService.updateById(microProcess));
    }

    /**
     * 删除流程设计
     *
     * @param id 流程设计ID
     */
    @SaCheckPermission("system:micro-process:remove")
    @Log(title = "流程设计管理", message = "删除流程设计")
    @DeleteMapping("/remove")
    public R<Void> remove(@RequestParam Long id) {
        return toAjax(processService.deleteById(id));
    }

}
